package edu.cuit.zhuyimeng.ticket.controller;

import edu.cuit.zhuyimeng.framework.common.result.CommonResult;
import edu.cuit.zhuyimeng.framework.common.result.HttpStatusCodeConstants;
import edu.cuit.zhuyimeng.ticket.exception.BuyTicketException;
import edu.cuit.zhuyimeng.ticket.exception.RefundTicketException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 票务异常处理类
 */
@ControllerAdvice
public class TicketExceptionHandler {

    @ExceptionHandler(BuyTicketException.class)
    @ResponseBody
    public CommonResult<Void> handleBuyTicketException(BuyTicketException e) {
        return CommonResult.error(HttpStatusCodeConstants.BAD_REQUEST,e.getMessage());
    }

    @ExceptionHandler(RefundTicketException.class)
    @ResponseBody
    public CommonResult<Void> handleRefundTicketException(RefundTicketException e) {
        return CommonResult.error(HttpStatusCodeConstants.BAD_REQUEST,e.getMessage());
    }

}
